<?php
/**
 * 我的简历页
 * 仲伟涛 2011-3
 */
class Resume_Page_MyResume extends Resume_Page_Abstract
{
	/*
	 * 数据表字段
	 */
	private $tblAreaPos        = array("uid","base","edu","lang","project","practice","offer","cert","training","position","schoolaward","other","photo");
	private $tblColOther       = array("id","uid","title","content");
	private $tblColSchoolAward = array("id","uid","title","date_month","date_year","intro","school");
	private $tblColPosition    = array("id","uid","title","from_year","from_month","to_year","to_month","to_now","school","intro");
	private $tblColLanguage    = array("id","userid","lang","oral","rw","grade_score","isdel");
	private $tblColProject     = array("id","name","teamsize","pro_desc","userid","duties","department","post","startyear","startmonth","endyear","endmonth","tonow","person_desc");
	private $tblColJob         = array("id","userid", "type", "company", "industry", "property", "scope", "department", "post", "startyear", "startmonth", "endyear", "endmonth", "onjob", "jobtype", "jobname", "descr");
	private $tblColJobHistory  = array("id","userid", "getyear","getmonth","jobtype","company","jobname");
	private $tblColTrain       = array("id","userid","name","institution","startyear","startmonth","endyear","endmonth","tonow","descr");
	private $tblColCert        = array("id","name","userid");
	private $tblColAttach      = array("id","userid","fileurl","filesize","filename");
	private $resumeDb;
	
	public function validate(ME_Request $input, ME_Response $output)
	{
		//获得登录的用户
		$input->jumpLogin   = true;
		$input->myLoginInfo = Libs_UcUser::checkLogin($input,$output);
		$output->uid        =
			$input->uid         =  (int)$input->myLoginInfo['uid'];

		$output->eid	    =
		$input->eid	    =
			       $eid = (int)$input->get("eid");

		$input->userName    = $input->myLoginInfo['userName'];
		$output->myResumeConfig = ME_Config::get("MyResume");
		$output->hasData    = array(); //标志每个区域是否有数据
		return true;
	}
	private function loadDb()
	{
		$this->resumeDb = Db_Resume::instance();
	}

	public function doDefault(ME_Request $input, ME_Response $output)
	{
		
		$this->loadDb();

		//区域隐藏信息
		$areaHideArr         = array("base"=>1,"edu"=>1,"lang"=>1,"project"=>1,"practice"=>1,"offer"=>1,"cert"=>1,"training"=>1,"it"=>1,"position"=>1,"schoolaward"=>1,"other"=>1,"photo"=>1);


		$areaHideArr2        = Resume_Plugin_MyResume::getAreaHideValueArr($input,$output);

		$output->areaHideArr = array_merge($areaHideArr,$areaHideArr2);

		$output->baseInfo = Resume_Plugin_MyResume::getBaseInfo($input,$output);
		if(!isset($areaHideArr['edu']) || $areaHideArr['edu']) $output->eduList = Resume_Plugin_MyResume::getEduInfo($input,$output);
		if(!isset($areaHideArr['other']) || $areaHideArr['other']) $output->otherList = Resume_Plugin_MyResume::getOtherInfo($input,$output);
		if(!isset($areaHideArr['schoolaward']) || $areaHideArr['schoolaward']) $output->schoolAwardList = Resume_Plugin_MyResume::getSchoolAwardInfo($input,$output);
		if(!isset($areaHideArr['position']) || $areaHideArr['position']) $output->positionList    = Resume_Plugin_MyResume::getPositionInfo($input,$output);

		$output->languageList = Resume_Plugin_MyResume::getLanguageInfo($input, $output);
		$output->projectList = Resume_Plugin_MyResume::getProjectInfo($input, $output);
		$output->jobList = Resume_Plugin_MyResume::getJobInfo($input, $output);
		$output->jobhistoryList = Resume_Plugin_MyResume::getJobHistoryInfo($input, $output);
		$output->trainList = Resume_Plugin_MyResume::getTrainInfo($input, $output);
		$output->certList = Resume_Plugin_MyResume::getCertInfo($input, $output);
		$output->itList = Resume_Plugin_MyResume::getITInfo($input, $output);
		$output->attachList = Resume_Plugin_MyResume::getAttachInfo($input, $output);

		//-----获取已经添加的it的熟练度-----

		$this->loadDb();
		$sql = "Select distinct familiar from resume_it where userid=".$input->uid;
		$fa_arr = $this->resumeDb->get_results($sql);

		$it_type_arr = array();
		if(!empty($fa_arr) && is_array($fa_arr)){
			foreach($fa_arr as $fa_key=>$fa_val){
				array_push($it_type_arr, $fa_val['familiar']);
			}
		}
		$output->it_type_arr = $it_type_arr;
		//------------------------
		$output->header = Resume_Plugin_Header::getHeader($input, $output);
		$output->footer = Resume_Plugin_Header::getFooter($input, $output);

		if($input->eid){
			$sql = "select name from e_user where id = ".$input->eid;
			$output->e_name =
                	$e_name = $this->resumeDb->getOne($sql);
		}

		$output->setTemplate('MyResume/Default');

	}

	//简历保存
	public function doSave(ME_Request $input, ME_Response $output){
		$output->header = Resume_Plugin_Header::getHeader($input, $output);
		$output->footer = Resume_Plugin_Header::getFooter($input, $output);
		$output->setTemplate('MyResume/Save');

	}
	/*ajax load一个公共区块*/
	public function doLoadTypeArea(ME_Request $input, ME_Response $output){
		$type = $input->get("type");
		echo call_user_func_array(array( 'Resume_Plugin_MyResume' , "get{$type}Info" ),array($input,$output));
		exit;
	}

	//获得各个区域的隐藏情况
	private function getAreaHideValueArr(ME_Request $input, ME_Response $output){
		$this->loadDb();
		$sql = "select * from resume_areapos where uid = ".$input->uid;
		$output->areaHideArr = $this->resumeDb->getRow($sql);
	}
	/**
	 * 显示隐藏一个区域
	 */
	public function doShowHideArea(ME_Request $input, ME_Response $output){
		$this->loadDb();
		$area = $input->get("area");
		$value = (int)$input->get("val");
		$value = $value >= 1 ? 1 : 0 ; // 1.显示，0，隐藏

		$sql = "select 'X' from resume_areapos where uid = ".$input->uid;
		$hasRec = $this->resumeDb->getOne($sql);
		if(!$hasRec){
			foreach($this->tblAreaPos as $p){
				$item[$p] = 1;
			}
		}
		$item['uid'] =  $input->uid;
		$item[$area] =  $value;

		$options = array(
				'db'        => $this->resumeDb,
				'tableName' => 'resume_areapos',
				'addItem'   => $item,
				'colArr'    => $this->tblAreaPos,
				);

		if($hasRec){//编辑
			$options['where'] = ' where uid = '.$input->uid;
			Libs_DBHelper::updateItem($options);
		}else{
			Libs_DBHelper::insertItem($options);
		}
		exit;
	}


	/**
	 * 基本信息管理
	 */
	public function doBaseInfoShow(ME_Request $input, ME_Response $output){

		$this->checkParam($input,$output);;
		$this->loadDb();
		$sql = "select * from resume_baseInfo where uid ={$input->uid} ";
		$dataInfo         =
			$output->dataInfo = $this->resumeDb->getRow($sql);
		$output->userUcInfo = Libs_UcUser::getUserInfo(array('nameOrId'=>$input->uid,'flag'=>'1'));
		//获得通用的数据
		$output->birthProvOptions = Libs_Admin_Module::getModuleSelect(array('selVal'=>$dataInfo['birthProv'],'module_type'=>1,'subclassid'=>0,'type'=>1,'pagesize'=>1000));
		$output->birthCityOptions = Libs_Admin_Module::getModuleSelect(array('selVal'=>$dataInfo['birthCity'],'module_type'=>1,'classid'=>$output->dataInfo['birthProv'],'type'=>2,'pagesize'=>1000));
		$output->regProvOptions = Libs_Admin_Module::getModuleSelect(array('selVal'=>$dataInfo['regProv'],'module_type'=>1,'subclassid'=>0,'type'=>1,'pagesize'=>1000));
		$output->regCityOptions = Libs_Admin_Module::getModuleSelect(array('selVal'=>$dataInfo['regCity'],'module_type'=>1,'classid'=>$output->dataInfo['regProv'],'type'=>2,'pagesize'=>1000));

		$output->setTemplate('MyResume/BaseInfo');
	}

	public function doBaseInfoEdit(ME_Request $input, ME_Response $output){

		$this->loadDb();
		$this->checkParam($input,$output);
		$id = (int)$input->post("id");
		$isAdd = (int)$input->post("isAdd");
		$item = $input->post("item");
		$mail = $input->post("mail");
		$options = array(
				'db'        => $this->resumeDb,
				'tableName' => 'resume_baseInfo',
				'addItem'   => $item,
				'colArr'    => array(),
				'debug'    => 1,
				);
		if(!$isAdd){//编辑
			$options['where'] = ' where uid = '.$input->uid;
			Libs_DBHelper::updateItem($options);
		}else{
			$options['addItem']['uid'] = $input->uid;
			Libs_DBHelper::insertItem($options);
			if($input->eid){
				$sql = "select id from resume_baseInfo where uid={$input->uid} and eid={$input->eid}";
				$b_id = $this->resumeDb->getOne($sql);
				if(!$b_id){
					$item['eid'] = $input->eid; 
					$options = array(
     	        	                	'db'        => $this->resumeDb,
        	        	        	'tableName' => 'resume_baseInfo',
                                		'addItem'   => $item,
                                		'colArr'    => array(),
                                		//'debug'    => 1,
                                	);
					Libs_DBHelper::insertItem($options);
				}
			}
		}
		//修改email部分
		if($mail){
			$userUcInfo = Libs_UcUser::getUserInfo(array('nameOrId'=>$input->uid,'flag'=>'1'));
			Libs_UcUser::editUserInfo(array('username'=>$userUcInfo['username'],'ignoreoldpw'=>1,'email'=>$mail));
		}
		echo "<script>self.parent.afterFrameAdd('Base')</script>";
		exit;

	}

	/**
	 * 教育  显示
	 */
	public function doEduShow(ME_Request $input, ME_Response $output){

		$this->checkParam($input,$output);
		$this->loadDb();
		$id = (int)$input->get("id");
		if($id){
			$sql = 'select * from resume_edu where uid='.$input->uid.' and  id=' . $id;
			$output->dataInfo = $this->resumeDb->getRow($sql);
			$output->id = $id;
		}
		$output->setTemplate('MyResume/EduAdd');
	}

	/**
	 * 教育  添加
	 */
	public function doEduAdd(ME_Request $input, ME_Response $output){
		$this->loadDb();
		$this->checkParam($input,$output);
		$id = (int)$input->post("id");
		$item = $input->post("item");
		$item['uid'] =  $input->uid;
		$options = array(
				'db'        => $this->resumeDb,
				'tableName' => 'resume_edu',
				'addItem'   => $item,
				'colArr'    => array(),
				//'debug'    => 1,
				);
		if($id){//编辑
			$options['where'] = ' where id = '.$id;
			Libs_DBHelper::updateItem($options);
		}else{
			Libs_DBHelper::insertItem($options);
			if($input->eid){
                                $sql = "select id from resume_edu where uid={$input->uid} and eid={$input->eid}";
                                $b_id = $this->resumeDb->getOne($sql);
                                if(!$b_id){
                                        $item['eid'] = $input->eid;
                                        $options = array(
                                                'db'        => $this->resumeDb,
                                                'tableName' => 'resume_edu',
                                                'addItem'   => $item,
                                                'colArr'    => array(),
                                                //'debug'    => 1,
                                        );
                                        Libs_DBHelper::insertItem($options);
                                }
                        }
		}
		echo "<script>self.parent.afterFrameAdd('Edu')</script>";
		exit;
	}


	/**
	 * 教育  删除
	 */
	public function doEduDel(ME_Request $input, ME_Response $output){
		$this->loadDb();
		$id = (int)$input->get("id");
		if($id){
			$sql = "delete from resume_edu where uid={$input->uid} and id = {$id}";
			$this->resumeDb->query($sql);
		}
		echo "1";
		exit;
	}


	/**
	 * 学校职务  显示
	 */
	public function doPositionShow(ME_Request $input, ME_Response $output){

		$this->checkParam($input,$output);
		$this->loadDb();
		$id = (int)$input->get("id");
		if($id){
			$sql = 'select * from resume_position where uid='.$input->uid.' and  id=' . $id;
			$output->dataInfo = $this->resumeDb->getRow($sql);
			$output->id = $id;
		}

		//学校信息
		$this->getScholList($input,$output);
		$output->setTemplate('MyResume/PositionAdd');
	}

	/**
	 * 学校职务  添加
	 */
	public function doPositionAdd(ME_Request $input, ME_Response $output){
		$this->loadDb();
		$this->checkParam($input,$output);
		$id = (int)$input->post("id");
		$title = trim($input->post("title"));
		$intor = trim($input->post("intro"));
		$item = array(
				'uid'   => $input->uid,
				'title' => $title,
				'from_month'=> (int)$input->post("from_month"),
				'from_year' => (int)$input->post("from_year"),
				'to_year'   => (int)$input->post("to_year"),
				'to_month'  => (int)$input->post("to_month"),
				'to_now'    => (int)$input->post("to_now"),
				'school'     => $input->post("school"),
				'intro' => $intor,
			     );
		$options = array(
				'db'        => $this->resumeDb,
				'tableName' => 'resume_position',
				'addItem'   => $item,
				'colArr'    => $this->tblColPosition,
				//'debug'    => 1,
				);
		if($id){//编辑
			$options['where'] = ' where id = '.$id;
			Libs_DBHelper::updateItem($options);
		}else{
			Libs_DBHelper::insertItem($options);
			if($input->eid){
                                $sql = "select id from resume_position where uid={$input->uid} and eid={$input->eid}";
                                $b_id = $this->resumeDb->getOne($sql);
                                if(!$b_id){
                                        $item['eid'] = $input->eid;
                                        $options = array(
                                                'db'        => $this->resumeDb,
                                                'tableName' => 'resume_position',
                                                'addItem'   => $item,
						'colArr'    => $this->tblColPosition,
                                        );
                                        Libs_DBHelper::insertItem($options);
                                }
                        }
		}
		echo "<script>self.parent.afterFrameAdd('Position')</script>";
		exit;
	}


	/**
	 * 学校职务  删除
	 */
	public function doPositionDel(ME_Request $input, ME_Response $output){
		$this->loadDb();
		$id = (int)$input->get("id");
		if($id){
			$sql = "delete from resume_position where uid={$input->uid} and id = {$id}";
			$this->resumeDb->query($sql);
		}
		echo "1";
		exit;
	}


	/**
	 * 学校奖励  显示
	 */
	public function doSchoolAwardShow(ME_Request $input, ME_Response $output){

		$this->checkParam($input,$output);
		$this->loadDb();
		$id = (int)$input->get("id");
		if($id){
			$sql = 'select * from resume_reward where uid='.$input->uid.' and  id=' . $id;
			$output->dataInfo = $this->resumeDb->getRow($sql);
			$output->id = $id;
		}
		//学校信息
		$this->getScholList($input,$output);
		$output->setTemplate('MyResume/SchoolAwardAdd');
	}



	/**
	 * 学校奖励  添加
	 */
	public function doSchoolAwardAdd(ME_Request $input, ME_Response $output){
		$this->loadDb();
		$this->checkParam($input,$output);
		$id = (int)$input->post("id");
		$title = trim($input->post("title"));
		$intor = trim($input->post("intro"));
		$item = array(
				'uid'   => $input->uid,
				'title' => $title,
				'date_month'=> (int)$input->post("date_month"),
				'date_year' => (int)$input->post("date_year"),
				'school'    => $input->post("school"),
				'intro' => $intor,
			     );
		$options = array(
				'db'        => $this->resumeDb,
				'tableName' => 'resume_reward',
				'addItem'   => $item,
				'colArr'    => $this->tblColSchoolAward,
				);
		if($id){//编辑
			$options['where'] = ' where id = '.$id;
			Libs_DBHelper::updateItem($options);
		}else{
			Libs_DBHelper::insertItem($options);
			if($input->eid){
                                $sql = "select id from resume_reward where uid={$input->uid} and eid={$input->eid}";
                                $b_id = $this->resumeDb->getOne($sql);
                                if(!$b_id){
                                        $item['eid'] = $input->eid;
                                        $options = array(
                                                'db'        => $this->resumeDb,
                                                'tableName' => 'resume_reward',
                                                'addItem'   => $item,
						'colArr'    => $this->tblColSchoolAward,
                                        );
                                        Libs_DBHelper::insertItem($options);
                                }
                        }
		}
		echo "<script>self.parent.afterFrameAdd('SchoolAward')</script>";
		exit;
	}

	/**
	 * 学校奖励  删除
	 */
	public function doSchoolAwardDel(ME_Request $input, ME_Response $output){
		$this->loadDb();
		$id = (int)$input->get("id");
		if($id){
			$sql = "delete from resume_reward where  uid={$input->uid} and id = {$id}";
			$this->resumeDb->query($sql);
		}
		echo "1";
		exit;
	}




	/**
	 * 其他信息  显示
	 */
	public function doOtherShow(ME_Request $input, ME_Response $output){

		$this->checkParam($input,$output);
		$this->loadDb();
		$id = (int)$input->get("id");
		if($id){
			$sql = 'select * from resume_other where uid='.$input->uid.' and  id=' . $id;
			$output->dataInfo = $this->resumeDb->getRow($sql);
			$output->id = $id;
		}
		$config = ME_Config::get("MyResume");
		$output->otherType = $config['otherType'];
		$output->setTemplate('MyResume/OtherAdd');
	}

	/**
	 * 其他信息  添加
	 */
	public function doOtherAdd(ME_Request $input, ME_Response $output){
		$this->loadDb();
		$this->checkParam($input,$output);
		$id = (int)$input->post("id");
		$title = (int)$input->post("title");
		$content = trim($input->post("content"));
		$item = array(
				'uid'   => $input->uid,
				'title' => $title,
				'content' => $content,
			     );
		$options = array(
				'db'        => $this->resumeDb,
				'tableName' => 'resume_other',
				'addItem'   => $item,
				'colArr'    => $this->tblColOther,
				);
		if($id){//编辑
			$options['where'] = ' where id = '.$id;
			Libs_DBHelper::updateItem($options);
		}else{
			Libs_DBHelper::insertItem($options);
			if($input->eid){
                                $sql = "select id from resume_other where uid={$input->uid} and eid={$input->eid}";
                                $b_id = $this->resumeDb->getOne($sql);
                                if(!$b_id){
                                        $item['eid'] = $input->eid;
                                        $options = array(
                                                'db'        => $this->resumeDb,
                                                'tableName' => 'resume_other',
                                                'addItem'   => $item,
						'colArr'    => $this->tblColOther,
                                        );
                                        Libs_DBHelper::insertItem($options);
                                }
                        }
		}
		echo "<script>self.parent.afterFrameAdd('Other')</script>";
		exit;
	}

	/**
	 * 其他信息  删除
	 */
	public function doOtherDel(ME_Request $input, ME_Response $output){
		$this->loadDb();
		$id = (int)$input->get("id");
		if($id){
			$sql = "delete from resume_other where  uid={$input->uid} and  id = {$id}";
			$this->resumeDb->query($sql);
		}
		echo "1";
		exit;
	}

	//获得学校的select 列表
	private function getScholList(ME_Request $input, ME_Response $output){

		$this->loadDb();
		$commonOption = array(
				'db'        => $this->resumeDb,
				'fromSql'   => 'from resume_edu',
				'whereSql'  => "where uid = {$input->uid}",
				'onlyData'  => true,
				);
		$output->eduList  =  Libs_DBHelper::getList($commonOption);
	}

	//基本的检查参数
	public function checkParam(ME_Request $input, ME_Response $output){
		return true;
	}






	//--------------------------------


	//语言能力
	public function doLanguageShow(ME_Request $input, ME_Response $output){
		$lang_list = Libs_Admin_Category::getCategoryList(array("module_type"=>2,"type"=>1));
		$list = array();
		if(!empty($lang_list) && is_array($lang_list)){
			foreach ($lang_list as $key=>$val){
				$classid = $val['classid'];
				$name = $val['name'];
				$list[$classid] = $name;
			}
		}

		$output->list = $list;
#语言精通程度
		$config = ME_Config::get("MyResume");
		$output->state = $config['state'];

#等级考试
		$gradeScore = Libs_Admin_Category::getCategoryList(array("module_type"=>2,"type"=>2));
		if(!empty($gradeScore) && is_array($gradeScore)){
			foreach ($gradeScore as $gradekey => $gradeval) {
				$examArr[$gradeval['classid']][$gradeval['subclassid']] = $gradeval['name'];
			}
		}
		$output->examArr = $examArr;

		$id = (int)$input->get("id");
		if($id){
			$this->loadDb();
			$sql = 'select * from resume_language where userid='.$input->uid.' and  id=' . $id;
			$output->dataInfo = 
			$dataInfo         = $this->resumeDb->getRow($sql);
			$output->id = $id;

			$subclassid = 0;
			$gradescore = 0;
			$grade_score = !empty($dataInfo['grade_score']) ? $dataInfo['grade_score'] : 0;
			if($grade_score != 0){
				$grade_info = explode(":",$grade_score);
				$subclassid = !empty($grade_info[0]) ? $grade_info[0] : 0;
				$gradescore = !empty($grade_info[1]) ? $grade_info[1] : 0;
			}
			$output->gradescore = $gradescore;
			$output->subclassid = $subclassid;

			if(!empty($subclassid)){
				$s_sql = "Select subclassid, name from category_list where classid=(select classid from category_list where subclassid=$subclassid) and subclassid!=0";
				$output->subclasslist =
				$subclasslist = $this->resumeDb->getAll($s_sql);
			}

		}

		$output->setTemplate("MyResume/LanguageAdd");
	}


	//语言能力添加
	public function doLanguageAdd(ME_Request $input, ME_Response $output){
		$this->loadDb();


		if($input->post("userid")){
			$userid = (int)$input->post("userid");
			$lang = (int)$input->post("lang");
			$oral = (int)$input->post("oral");
			$rw = (int)$input->post("rw");
			$grade = $input->post("grade");
			$score = $input->post("score");

			$grade_score = '';
			if(!empty ($grade) && !empty($score)){
				foreach ($grade as $key=>$value){
					$score_val = !empty($score[$key]) ? $score[$key] : 0;
					$grade_score .= $value.":".$score_val.",";
				}
			}
			$grade_score = rtrim($grade_score,',');
			$item = array(
					'userid'   => $input->uid,
					'lang' => $lang,
					'oral' => $oral,
					'rw'   => $rw,
					'grade_score'=>$grade_score,
					'isdel'=> 0
				     );
			$options = array(
					'db'        => $this->resumeDb,
					'tableName' => 'resume_language',
					'addItem'   => $item,
					'colArr'    => $this->tblColLanguage,
					);
			$id = $input->post('id');
			if($id){//编辑
				$options['where'] = ' where id = '.$id;
				Libs_DBHelper::updateItem($options);
			}else{
				Libs_DBHelper::insertItem($options);
				if($input->eid){
                                	$sql = "select id from resume_language where userid={$input->uid} and eid={$input->eid}";
                                	$b_id = $this->resumeDb->getOne($sql);
                                	if(!$b_id){
                                        	$item['eid'] = $input->eid;
                                        	$options = array(
                                                	'db'        => $this->resumeDb,
                                                	'tableName' => 'resume_language',
                                                	'addItem'   => $item,
							'colArr'    => $this->tblColLanguage,
                                       		);
                                        	Libs_DBHelper::insertItem($options);
                                	}
                        	}
			}
		}

		echo "<script>self.parent.afterFrameAdd('Language')</script>";
		exit;
	}

	/**
	 * 语言能力  删除
	 */
	public function doLanguageDel(ME_Request $input, ME_Response $output){
		$this->loadDb();
		$id = (int)$input->get("id");
		if($id){
			$sql = "delete from resume_language where  userid={$input->uid} and  id = {$id}";
			$this->resumeDb->query($sql);
		}
		echo "1";
		exit;
	}


	//项目经验
	public function doProjectShow(ME_Request $input, ME_Response $output){

		$id = (int)$input->get("id");
		if($id){
			$this->loadDb();
			$sql = 'select * from resume_project where userid='.$input->uid.' and  id=' . $id;
			$output->dataInfo = $this->resumeDb->getRow($sql);

			$output->id = $id;
		}

#团队规模
		$config = ME_Config::get("MyResume");
		$output->teamsize = $config['teamsize'];

		$output->setTemplate("MyResume/ProjectAdd");
	}


	//项目经验添加
	public function doProjectAdd(ME_Request $input, ME_Response $output){
		$this->loadDb();


		if($input->post("userid")){
			$userid = (int)$input->post("userid");
			$name = $input->post("name");
			$teamsize = (int)$input->post("teamsize");
			$pro_desc = $input->post("pro_desc");
			$duties = $input->post("duties");
			$department = $input->post("department");
			$post = $input->post("post");
			$start_year = $input->post("start_year");
			$start_month = $input->post("start_month");
			$end_year = $input->post("end_year");
			$end_month = $input->post("end_month");
			$tonow = $input->post("tonow");
			$achievement = $input->post("achievement");

			$item = array(
					'userid'   => $input->uid,
					'name'     => $name,
					'teamsize' => $teamsize,
					'pro_desc' => $pro_desc,
					'duties'   => $duties,
					'department'=>$department,
					'post'      => $post,
					'startyear'=> $start_year,
					'startmonth'=> $start_month,
					'endyear'   => $end_year,
					'endmonth'  => $end_month,
					'tonow'      => $tonow,
					'person_desc'=> $achievement

				     );
			$options = array(
					'db'        => $this->resumeDb,
					'tableName' => 'resume_project',
					'addItem'   => $item,
					'colArr'    => $this->tblColProject,
					);
			$id = $input->post('id');
			if($id){//编辑
				$options['where'] = ' where id = '.$id;
				Libs_DBHelper::updateItem($options);
			}else{
				Libs_DBHelper::insertItem($options);
				if($input->eid){
                                        $sql = "select id from resume_project where userid={$input->uid} and eid={$input->eid}";
                                        $b_id = $this->resumeDb->getOne($sql);
                                        if(!$b_id){
                                                $item['eid'] = $input->eid;
                                                $options = array(
                                                        'db'        => $this->resumeDb,
                                                        'tableName' => 'resume_project',
                                                        'addItem'   => $item,
                                                        'colArr'    => $this->tblColProject,
                                                );
                                                Libs_DBHelper::insertItem($options);
                                        }
                                }
			}

		}

		echo "<script>self.parent.afterFrameAdd('Project')</script>";
		exit;
	}

	/**
	 * 项目经验  删除
	 */
	public function doProjectDel(ME_Request $input, ME_Response $output){
		$this->loadDb();
		$id = (int)$input->get("id");
		if($id){
			$sql = "delete from resume_project where  userid={$input->uid} and  id = {$id}";
			$this->resumeDb->query($sql);
		}
		echo "1";
		exit;
	}


	//工作经历
	public function doJobShow(ME_Request $input, ME_Response $output){
		$config = ME_Config::get("MyResume");
                $output->jobtype = $config['jobtype'];

		$id = (int)$input->get("id");
		if($id){
			$this->loadDb();
			$sql = 'select * from resume_job where userid='.$input->uid.' and  id=' . $id;
			$output->dataInfo = $this->resumeDb->getRow($sql);
			$output->id = $id;
		}

		$output->setTemplate("MyResume/JobAdd");
	}


	//工作经历添加
	public function doJobAdd(ME_Request $input, ME_Response $output){
		$this->loadDb();
                
		if($input->post("userid")){
			$userid = (int)$input->post("userid");
			$type = (int)$input->post("type");
			$company = $input->post("company");
			$company = addslashes(trim($company));
			$industry = (int)$input->post("industry");
			$property = (int)$input->post("property");
			$scope = (int)$input->post("scope");
			$department = $input->post("department");
			$department = addslashes(trim($department));
			$post = $input->post("post");
			$post = addslashes(trim($post));
			$startyear = (int)$input->post("startyear");
			$startmonth = (int)$input->post("startmonth");
			$endyear = (int)$input->post("endyear");
			$endmonth = (int)$input->post("endmonth");
			$onjob = (int)$input->post("onjob");
			$jobtype = (int)$input->post("jobtype");
			$jobname = (int)$input->post("jobname");
			$desc = $input->post("desc");
			$desc = addslashes(trim($desc));

			$item = array(
					'userid'   => $input->uid,
					'type'     => $type,
					'company'  => $company,
					'industry' => $industry,
					'property' => $property,
					'scope'    => $scope,
					'department' => $department,
					'post' => $post,
					'startyear' => $startyear,
					'startmonth'   => $startmonth,
					'endyear'   =>$endyear,
					'endmonth'  => $endmonth,
					'onjob'     => $onjob,
					'jobtype'   => $jobtype,
					'jobname'   => $jobname,
					'descr'     => $desc
				     );
			$options = array(
					'db'        => $this->resumeDb,
					'tableName' => 'resume_job',
					'addItem'   => $item,
					'colArr'    => $this->tblColJob,
					);
			$id = $input->post('id');
			if($id){//编辑
				$options['where'] = ' where id = '.$id;
				Libs_DBHelper::updateItem($options);
			}else{
				Libs_DBHelper::insertItem($options);
				if($input->eid){
                                        $sql = "select id from resume_job where userid={$input->uid} and eid={$input->eid}";
                                        $b_id = $this->resumeDb->getOne($sql);
                                        if(!$b_id){
                                                $item['eid'] = $input->eid;
                                                $options = array(
                                                        'db'        => $this->resumeDb,
                                                        'tableName' => 'resume_job',
                                                        'addItem'   => $item,
							'colArr'    => $this->tblColJob,
                                                );
                                                Libs_DBHelper::insertItem($options);
                                        }
                                }
			}

		}

		echo "<script>self.parent.afterFrameAdd('Job')</script>";
		exit;
	}

	/**
	 * 工作实习经历  删除
	 */
	public function doJobDel(ME_Request $input, ME_Response $output){
		$this->loadDb();
		$id = (int)$input->get("id");
		if($id){
			$sql = "delete from resume_job where  userid={$input->uid} and  id = {$id}";
			$this->resumeDb->query($sql);
		}
		echo "1";
		exit;
	}


	//工作经历
	public function doJobHistoryShow(ME_Request $input, ME_Response $output){

		$id = (int)$input->get("id");
		if($id){
			$this->loadDb();
			$sql = 'select * from resume_jobhistory where userid='.$input->uid.' and  id=' . $id;
			$output->dataInfo = $this->resumeDb->getRow($sql);
			$output->id = $id;
		}

		$config = ME_Config::get("MyResume");
		$output->jobhistorytype = $config['jobhistorytype'];

		$output->setTemplate("MyResume/JobHistoryAdd");
	}

	//工作经历添加
	public function doJobHistoryAdd(ME_Request $input, ME_Response $output){
		$this->loadDb();


		if($input->post("userid")){
			$userid = (int)$input->post("userid");
			$getyear = (int)$input->post("getYear");
			$getmonth = (int)$input->post("getMonth");
			$type = (int)$input->post("type");
			$company = $input->post("company");
			$jobname = $input->post("jobname");

			$item = array(
					'userid'   => $input->uid,
					'getyear'  => $getyear,
					'getmonth' => $getmonth,
					'jobtype'   => $type,
					'company'  => $company,
					'jobname'   => $jobname
				     );
			$options = array(
					'db'        => $this->resumeDb,
					'tableName' => 'resume_jobhistory',
					'addItem'   => $item,
					'colArr'    => $this->tblColJobHistory,
					);
			$id = $input->post('id');
			if($id){//编辑
				$options['where'] = ' where id = '.$id;
				Libs_DBHelper::updateItem($options);
			}else{
				Libs_DBHelper::insertItem($options);
				if($input->eid){
                                        $sql = "select id from resume_jobhistory where userid={$input->uid} and eid={$input->eid}";
                                        $b_id = $this->resumeDb->getOne($sql);
                                        if(!$b_id){
                                                $item['eid'] = $input->eid;
                                                $options = array(
                                                        'db'        => $this->resumeDb,
                                                        'tableName' => 'resume_jobhistory',
                                                        'addItem'   => $item,
							'colArr'    => $this->tblColJobHistory,
                                                );
                                                Libs_DBHelper::insertItem($options);
                                        }
                                }
			}
		}

		echo "<script>self.parent.afterFrameAdd('JobHistory')</script>";
		exit;
	}

	/**
	 * 工作实习经历  删除
	 */
	public function doJobHistoryDel(ME_Request $input, ME_Response $output){
		$this->loadDb();
		$id = (int)$input->get("id");
		if($id){
			$sql = "delete from resume_jobhistory where  userid={$input->uid} and  id = {$id}";
			$this->resumeDb->query($sql);
		}
		echo "1";
		exit;
	}


	//培训经历
	public function doTrainShow(ME_Request $input, ME_Response $output){

		$id = (int)$input->get("id");
		if($id){
			$this->loadDb();
			$sql = 'select * from resume_train where userid='.$input->uid.' and  id=' . $id;
			$output->dataInfo = $this->resumeDb->getRow($sql);
			$output->id = $id;
		}

		$output->setTemplate("MyResume/TrainAdd");
	}

	//培训经历添加
	public function doTrainAdd(ME_Request $input, ME_Response $output){
		$this->loadDb();


		if($input->post("userid")){
			$userid = (int)$input->post("userid");
			$name = $input->post("name");
			$name = addslashes(trim($name));
			$institution = $input->post("institution");
			$institution = addslashes(trim($institution));
			$startyear = (int)$input->post("startyear");
			$startmonth = (int)$input->post("startmonth");
			$endyear = (int)$input->post("endyear");
			$endyear = !empty ($endyear) ? $endyear : 0;
			$endmonth = (int)$input->post("endmonth");
			$endmonth = !empty ($endmonth) ? $endmonth : 0;
			$tonow = (int)$input->post("tonow");
			$tonow = !empty ($tonow) ? $tonow : 0;
			$descr = $input->post("descr");
			$descr = addslashes(trim($descr));

			$item = array(
					'userid'        => $input->uid,
					'name'          => $name,
					'institution'   => $institution,
					'startyear'     => $startyear,
					'startmonth'    => $startmonth,
					'endyear'       => $endyear,
					'endmonth'      => $endmonth,
					'tonow'         => $tonow,
					'descr'         => $descr
				     );
			$options = array(
					'db'        => $this->resumeDb,
					'tableName' => 'resume_train',
					'addItem'   => $item,
					'colArr'    => $this->tblColTrain,
					);
			$id = $input->post('id');
			if($id){//编辑
				$options['where'] = ' where id = '.$id;
				Libs_DBHelper::updateItem($options);
			}else{
				Libs_DBHelper::insertItem($options);
				if($input->eid){
                                        $sql = "select id from resume_train where userid={$input->uid} and eid={$input->eid}";
                                        $b_id = $this->resumeDb->getOne($sql);
                                        if(!$b_id){
                                                $item['eid'] = $input->eid;
                                                $options = array(
                                                        'db'        => $this->resumeDb,
                                                        'tableName' => 'resume_train',
                                                        'addItem'   => $item,
							'colArr'    => $this->tblColTrain,
                                                );
                                                Libs_DBHelper::insertItem($options);
                                        }
                                }
			}

		}

		echo "<script>self.parent.afterFrameAdd('Train')</script>";
		exit;
	}

	/**
	 * 培训经历  删除
	 */
	public function doTrainDel(ME_Request $input, ME_Response $output){
		$this->loadDb();
		$id = (int)$input->get("id");
		if($id){
			$sql = "delete from resume_train where  userid={$input->uid} and  id = {$id}";
			$this->resumeDb->query($sql);
		}
		echo "1";
		exit;
	}

	//获得证书
	public function doCertShow(ME_Request $input, ME_Response $output){

		$this->loadDb();
		$sql = 'select id, name from resume_cert where userid='.$input->uid;
		$dataInfo = $this->resumeDb->getRow($sql);

		$existDidArr = array();

		if(!empty($dataInfo) && is_array($dataInfo)){
			foreach ($dataInfo as $dval){
				array_push($existDidArr, $dval['id']);
			}
		}
		$output->existDidArr = $existDidArr;

		$config = ME_Config::get("MyResume");
		$output->cert = $config['cert'];


		$output->setTemplate("MyResume/CertAdd");
	}

	//获得证书添加
	public function doCertAdd(ME_Request $input, ME_Response $output){
		$this->loadDb();

		$config = ME_Config::get("MyResume");
		$cert_k_v = $config['cert_k_v'];

		if($input->post("userid")){
			$userid = (int)$input->post("userid");
			$certid = $input->post("certid");

			if(!empty($certid) && is_array($certid)){
				foreach($certid as $id){
					$sql = "select id from resume_cert where id='{$id}' and userid='{$userid}' limit 1";
					$re_id = $this->resumeDb->getOne($sql);
					if(empty ($re_id)){
						$certname = $cert_k_v[$id];
						$u_sql = "insert into resume_cert(id,name,userid) values('{$id}','{$certname}','{$userid}')";
						$this->resumeDb->query($u_sql);
					}
				}
			}
		}

		echo "<script>self.parent.afterFrameAdd('Cert')</script>";
		exit;
	}

	/**
	 * 获得证书  删除
	 */
	public function doCertDel(ME_Request $input, ME_Response $output){
		$this->loadDb();
		$id = (int)$input->get("id");
		if($id){
			$sql = "delete from resume_cert where  userid={$input->uid} and id = {$id}";
			$this->resumeDb->query($sql);
		}
		echo "1";
		exit;
	}


	//获得it技能
	public function doITShow(ME_Request $input, ME_Response $output){

		$type = (int)$input->get("type");
		$type = !empty ($type) ? $type : 1;
		$output->type = $type;

		if(!empty($type)){
			$this->loadDb();
			$sql = 'select id, name from resume_it where userid='.$input->uid.' and familiar="'.$type.'"';
			//echo $sql;exit;
			$dataInfo = $this->resumeDb->get_results($sql);

			$id_arr = array();
			if(!empty ($dataInfo) && is_array($dataInfo)){
				foreach ($dataInfo as $d_key => $d_val) {
					array_push($id_arr, $d_val['id']);
				}
			}
			$output->id_arr = $id_arr;
		}


		$config = ME_Config::get("MyResume");
		$output->itSkill = $config['itSkill'];


		$output->setTemplate("MyResume/ITAdd");
	}

	//获得证书添加
	public function doITAdd(ME_Request $input, ME_Response $output){
		$this->loadDb();

		$config = ME_Config::get("MyResume");
		$itSkill_k_v = $config['itSkill_k_v'];

		if($input->post("userid")){
			$userid = (int)$input->post("userid");
			$itid = $input->post("itid");
			$type = $input->post("type");
			$itid = array_unique($itid);
			if(!empty($itid) && is_array($itid)){
				foreach($itid as $id){
					$sql = "select id from resume_it where id='{$id}' and userid='{$userid}' limit 1";
					$re_id = $this->resumeDb->getOne($sql);
					if(empty ($re_id)){
						$itname = $itSkill_k_v[$id];
						$u_sql = "insert into resume_it(id,name,userid,familiar) values('{$id}','{$itname}','{$userid}','{$type}')";
						$this->resumeDb->query($u_sql);
					}
				}
			}
		}

		echo "<script>self.parent.afterITAdd('IT')</script>";
		exit;
	}

	/**
	 * 获得证书  删除
	 */
	public function doITDel(ME_Request $input, ME_Response $output){
		$this->loadDb();
		$id = (int)$input->get("id");
		if($id){
			$sql = "delete from resume_it where  userid={$input->uid} and familiar = {$id}";
			$this->resumeDb->query($sql);
		}
		echo "1";
		exit;
	}

	//获得附件
	public function doAttachShow(ME_Request $input, ME_Response $output){

		$this->loadDb();
		$sql = 'select id, filename,fileurl from resume_attach where userid='.$input->uid;
		$output->$dataInfo = $this->resumeDb->getRow($sql);

		$output->setTemplate("MyResume/AttachAdd");
	}

	//Attach添加
	public function doAttachAdd(ME_Request $input, ME_Response $output){
		$this->loadDb();
		$y = date("Y",time());
		$m = date("m",time());
		$fileurl = array();
		$files = $input->files("resumefile");
		$f_upload = new Libs_FileUpload;
		$f_upload->upload_file();
		$f_upload->set_file_type($files['type']);   # 获得文件类型
		$f_upload->set_file_name($files['name']);   # 获得文件名称
		$f_upload->set_file_size($files['size']);   # 获得文件尺寸
		$f_upload->set_upfile($files['tmp_name']);  # 服务端储存的临时文件名
		$f_upload->set_size(2000);               # 设置最大上传KB数
		$f_upload->set_base_directory("upload");    # 文件存储根目录名称
		
		$f_upload->save();    #保存文件
		$path = $f_upload->file_path;
		$filesize = $f_upload->upfile_size;
		if($input->post("uid")){
			$userid = (int)$input->post("userid");
			$filename = $input->post("filename");
			//$fileurl = $input->post("resumefile");

			$item = array(
					'userid'        => $input->uid,
					'fileurl'       => $path,
					'filesize'       => $filesize,
					'filename'      => $filename,
				     );
			$options = array(
					'db'        => $this->resumeDb,
					'tableName' => 'resume_attach',
					'addItem'   => $item,
					'colArr'    => $this->tblColAttach,
					);
			$id = $input->post('id');
			if($id){//编辑
				$options['where'] = ' where id = '.$id;
				Libs_DBHelper::updateItem($options);
			}else{
				Libs_DBHelper::insertItem($options);
			}
		}

		echo "<script>self.parent.afterFrameAdd('Attach')</script>";
		exit;
	}

	/**
	 * Attach 删除
	 */
	public function doAttachDel(ME_Request $input, ME_Response $output){
		$this->loadDb();
		$id = (int)$input->get("id");
		if($id){
			$sql = "delete from resume_attach where id = {$id}";
			$this->resumeDb->query($sql);
		}
		echo "1";
		exit;
	}

}

?>
